<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>openNewWindow</title>
</head>

<body>
    <button type="button" id="testBtn">点击我打开新页面</button>
    <script>
        const openNewWindow = (url, linkOption = {
            target: '_blank',
            rel: 'noopener noreferrer'
        }) => {
            const link = document.createElement('a');
            link.href = url;
            if (typeof linkOption === 'object' && linkOption && Object.keys(linkOption).length > 0) {
                Object.keys(linkOption).forEach(key => {
                    link[key] = linkOption[key];
                });
            }
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        };
        document.getElementById('testBtn').onclick = () => openNewWindow('https://www.eveningwater.com');
    </script>
</body>

</html>